package com.backapp.app;

import java.util.*;

import com.dropbox.client2.*;
import com.dropbox.client2.DropboxAPI.*;
import com.dropbox.client2.android.*;
import com.dropbox.client2.exception.*;

import android.os.*;

public class DBLister extends AsyncTask<Void, Void, List<Entry>>
{
	private DropboxAPI<AndroidAuthSession> mDBApi;
	private DBListingListener mListener;
	
	public
	DBLister(
		DropboxAPI<AndroidAuthSession> DBApi,
		DBListingListener listener 
		)
	{
		mDBApi = DBApi;
		mListener = listener;
	}
	
	@Override
	protected List<Entry>
	doInBackground(Void... arg0)
	{
		try
		{
			return getMetaData();
		} 
		catch (DropboxException e)
		{
			Utils.logError(e.toString());
		}
		
		return null;
	}

    
    private List<Entry>
    getMetaData() 
	throws DropboxException
    {
    	Entry dirEntry;
    	
		dirEntry = mDBApi.metadata("/backapp/appdata/", 10000, null, true, null);
		
		return dirEntry.contents;
	}
    
    @Override
    protected void 
    onPostExecute(
    		List<Entry> result
    		)
    {
    	super.onPostExecute(result);
    	mListener.metaDataAvailable(result);
    }
}
